<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll"
export default {
  name:"Scroll",
  props:{
    probeType:{
      type:Number,
      default:0
    }
  },
  data(){
    return {
      scroll:null,
      message:"hahhaahha"
    }
  },
  mounted(){
    this.scroll=new BScroll(this.$refs.wrapper,{
      observeDOM:true,
      //允许监听点击
      click:true,
      // //滚动事件
      probeType:this.probeType,
      // //允许上拉加载更多
      pullUpLoad:true
    }),
    //监听滚动的位置
    this.scroll.on('scroll',position=>{
      // console.log(position)
      //将滚动的位置信息传到首页供backTop组件使用
      this.$emit('scrollInfo',position)
    })
    //监听上拉加载
    this.scroll.on('pullingUp',()=>{
      this.$emit('pullingUP')
    })
  },
  methods:{
    scrollTo(x,y,time=500){
      //将scroll实例对象的scrollTo方法封装起来
      this.scroll.scrollTo(x,y,time) 
    },
    finishPullUp(){
      this.scroll.finishPullUp()
    }
    
  }
}
</script>

<style scoped>
</style>